package com.itheima.admin.controller;

import com.itheima.PageVo;
import com.itheima.Result;
import com.itheima.admin.dto.ModuleDto;
import com.itheima.admin.dto.PageDto;
import com.itheima.admin.dto.PageModuleDto;
import com.itheima.admin.service.ModuleService;
import com.itheima.admin.vo.ModulePageVo;
import com.itheima.admin.vo.ModuleVo;
import com.itheima.admin.vo.ModuleVo2;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ModuleController
 * @Description TODO
 * @Author Mister-Lu
 * @Date 2021/12/17
 **/
@RestController
@RequestMapping("/module")
@CrossOrigin
public class ModuleController {
    @Autowired
    private ModuleService moduleService;

    @PostMapping("/list")
    @ApiOperation("模块数据条件分页查询")
    public PageVo<ModulePageVo> queryModulePage(@RequestBody PageModuleDto pageModuleDto){
        return moduleService.queryModulePage(pageModuleDto);
    }

    //@GetMapping("/listall")
    //@ApiOperation("查询所有模块")
    //public List<ModuleDto> queryAll(){
    //    return moduleService.queryAllModules();
    //}

    @GetMapping("/listall")
    @ApiOperation("查询所有模块")
    public List<ModuleVo2> queryAll(){
        List<ModuleVo2> entities = moduleService.queryMenuList();
        return entities;
    }

    @PostMapping("/add")
    @ApiOperation("新增模块")
    public Result addModule(@RequestBody ModuleDto moduleDto) {
       return moduleService.add(moduleDto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除模块")
    public Result deleteModuleById(@PathVariable("id") String id) {
        return moduleService.deleteModuleById(id);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询模块")
    public ModuleVo queryModuleById(@PathVariable("id") String id){
        return moduleService.queryModuleById(id);
    }

    @PutMapping("/edit")
    @ApiOperation("修改模块、添加部门")
    public Result updateModule(@RequestBody ModuleVo moduleVo){
       return moduleService.updateModule(moduleVo);
    }

}
